home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_07 / 2n07041a < prev    next >
Text File  |  1991-06-01  |  6KB  |  232 lines

  1. /*
  2.  * Support routines for the Animated Cursor Demo Program
  3.  * Written by Alex Leavens, for ShadowCat Technologies
  4.  *
  5.  * Created: 10/May/91
  6.  * Revised: 12/May/91
  7.  */
  8.  
  9.  
  10. #include <WINDOWS.H>
  11. #include "CURSOR.H"
  12.  
  13. /*-------------------------- Local variables ----------------------*/
  14.     
  15. BOOL    whirling;               /* Cursor spinning or not */
  16. WORD    whichWatch;             /* Current watch value */
  17.  
  18. WORD    speed;                  /* How fast to go... */
  19.  
  20. /*-------------------------- Function prototypes ------------------*/
  21.  
  22. void FAR PASCAL         Whirly(BOOL);
  23. void FAR PASCAL         SetCursorBusy(void);
  24. void NEAR PASCAL        DisableMenuEntries(HWND);
  25. void NEAR PASCAL        CheckSpeedMenu(HWND, WORD);
  26.  
  27. /******************************
  28.  *
  29.  * Quit()
  30.  *   Quits the demo program
  31.  *
  32.  */
  33.  
  34.     BOOL FAR PASCAL
  35. QuitFunc(HWND           hWnd,
  36.          unsigned       message,
  37.          WORD           wParam,
  38.          LONG           lParam)
  39. {
  40.     PostMessage(hWnd, WM_CLOSE, 0, 0L);
  41.     return TRUE;
  42. }
  43.  
  44. /************************
  45.  *
  46.  * SetSpeed()
  47.  *   Sets the speed to the desired setting
  48.  *
  49.  */
  50.  
  51.     BOOL FAR PASCAL
  52. SetSpeed(HWND hWnd, unsigned message,
  53.        WORD wParam, LONG lParam)
  54. {
  55.     static int speeds[4] = { 1000, 600, 400, 200 };
  56.     speed = speeds[wParam-IDM_Speed1];
  57.  
  58.     DisableMenuEntries(hWnd);   /* Uncheck all speed entries */
  59.     CheckSpeedMenu(hWnd, wParam);
  60.     return TRUE;
  61. }
  62.  
  63. /*******************************
  64.  *
  65.  * Animate()
  66.  *   Plays the cursor animation back at the currently
  67.  * selected speed.
  68.  */
  69.  
  70.     BOOL FAR PASCAL
  71. Animate(HWND            hWnd,
  72.         unsigned        message,
  73.         WORD            wParam,
  74.         LONG            lParam)
  75. {
  76.     int         i;
  77.     WORD        j;
  78.     WORD        k;
  79.     WORD        foo;
  80.  
  81.     Whirly(TRUE);
  82.  
  83.     for (i = 0; i < 50; i++)
  84.     {
  85.         foo = 0;
  86.         
  87.         for (j = 0; j < speed; j++)
  88.         {
  89.             for (k = 0; k < speed; k++)
  90.             {
  91.                 foo++;
  92.             }
  93.         }
  94.         Whirly(TRUE);
  95.     }
  96.  
  97.     Whirly(FALSE);
  98.  
  99.     return TRUE;
  100. }
  101.  
  102. /***********************************
  103.  *
  104.  * HandleCursorSet()
  105.  *   Handles the message when Windows wants to set the cursor.
  106.  *
  107.  * Arguments:
  108.  *      hWnd    - handle to the window that the message is destined for
  109.  *      message - what the message is
  110.  *      wParam  - points to the window handle that contains the cursor
  111.  *      lParam  - in the loword: hit test code
  112.  *                in the hiword: mouse message number
  113.  *
  114.  * Returns:
  115.  *      TRUE if we processed the event
  116.  *      the return from DefWindowProc() if Windows handled the event
  117.  *  
  118.  */
  119.  
  120.     long FAR PASCAL
  121. HandleCursorSet(HWND     hWnd,
  122.                 unsigned message, 
  123.                 WORD     wParam, 
  124.                 LONG     lParam)
  125. {
  126.     int hitTest;
  127.     
  128.     if (wParam != MainhWnd)     /* If not our window, then don't change */
  129.         return DefWindowProc(hWnd, message, wParam, lParam);
  130.     
  131.     hitTest = LOWORD(lParam);   /* Get cursor position within window */
  132.  
  133.     if (hitTest != HTCLIENT)    /* If not in client area, let
  134.                                  * Windows handle it.
  135.                                  */
  136.         return DefWindowProc(hWnd, message, wParam, lParam);
  137.  
  138.     if (whirling)               /* Are we spinning the stopwatch? */
  139.         return TRUE;            /* If yes, don't let Windows change the */
  140.     else                        /* cursor, otherwise, let Windows 
  141.                                  * handle the message.
  142.                                  */
  143.         return DefWindowProc(hWnd, message, wParam, lParam);
  144. }
  145.  
  146. /************************
  147.  *
  148.  * Whirly()
  149.  *   Animates the busy cursor, and updates the index into which
  150.  * image we'll need to use next.
  151.  *
  152.  */
  153.  
  154.     void FAR PASCAL
  155. Whirly(BOOL hitWhirly)
  156. {
  157.     if (hitWhirly)
  158.         whirling = TRUE;
  159.     else
  160.     {
  161.         whirling = FALSE;
  162.         return;
  163.     }
  164.  
  165.     SetCursorBusy();
  166.  
  167.     whichWatch++;
  168.  
  169.     if (whichWatch > 7)
  170.         whichWatch = 0;
  171. }
  172.  
  173. /*******************
  174.  *
  175.  * SetCursorBusy()
  176.  *   Sets the cursor to one of 8 possible images of a stopwatch;
  177.  * when done in sequence, the stopwatch appears animated.
  178.  *
  179.  */
  180.  
  181.     void FAR PASCAL
  182. SetCursorBusy()
  183. {
  184.     HCURSOR     loadCur;
  185.     static char cursorName[] = "WATCH ";
  186.  
  187.     if(whichWatch >= 8)
  188.         whichWatch  = 0;
  189.     cursorName[5]   = '1' + whichWatch;
  190.  
  191.     loadCur = LoadCursor(hInst,cursorName);
  192.     if (loadCur != NULL)
  193.         SetCursor(loadCur);
  194. }
  195. /************************
  196.  *
  197.  * DisableMenuEntries()
  198.  *   Unchecks all of the speed settings in the menu
  199.  *
  200.  */
  201.  
  202.     void NEAR PASCAL
  203. DisableMenuEntries(HWND hWnd)
  204. {
  205.     HMENU       hMenu;          /* Menu handle... */
  206.  
  207.     hMenu = GetMenu(hWnd);      /* Get handle to the menu */
  208.  
  209.     CheckMenuItem(hMenu, IDM_Speed1, MF_UNCHECKED);
  210.     CheckMenuItem(hMenu, IDM_Speed2, MF_UNCHECKED);
  211.     CheckMenuItem(hMenu, IDM_Speed3, MF_UNCHECKED);
  212.     CheckMenuItem(hMenu, IDM_Speed4, MF_UNCHECKED);
  213. }
  214. /**************************
  215.  *
  216.  * CheckSpeedMenu()
  217.  *   Checks the requested speed menu entry
  218.  *
  219.  */
  220.  
  221.     void NEAR PASCAL
  222. CheckSpeedMenu(HWND     hWnd,
  223.                WORD     entry)
  224. {
  225.     HMENU       hMenu;          /* Menu handle... */
  226.  
  227.     hMenu = GetMenu(hWnd);      /* Get handle to the menu */
  228.  
  229.     CheckMenuItem(hMenu, entry, MF_CHECKED);
  230. }              
  231.  
  232.